package org.lookahead.parent.apidoc.enums;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@AllArgsConstructor
@Getter
public enum SchoolUserTypeEnum {

    /**
     * 学校用户类型 0. 总负责人  1.分校负责人  2. 老师（班主任  助教） 3. 销售  4. 财务
     */
    MASTER_SCHOOL_PRINCIPAL(0, "总负责人"),
    SLAVE_SCHOOL_PRINCIPAL(1, "分校负责人"),
    TEACHER(2, "班主任，助教"),
    SALESPERSON(3, "销售"),
    TREASURER(4, "财务"),
    ;

    private static final Map<Integer, SchoolUserTypeEnum> schoolUserTypeEnumMap = new HashMap<>();

    static {
        for (SchoolUserTypeEnum schoolUserTypeEnum : SchoolUserTypeEnum.values()) {
            schoolUserTypeEnumMap.put(schoolUserTypeEnum.getUserCode(), schoolUserTypeEnum);
        }
    }

    @Schema(description = "用户类型编码")
    private final Integer userCode;

    @Schema(description = "用户类型名称")
    private final String userTypeName;

    public static SchoolUserTypeEnum getSchoolUserTypeEnum(Integer userCode) {
        return schoolUserTypeEnumMap.getOrDefault(userCode, null);
    }

    public static Boolean isSchoolMaster(Integer userCode) {
        return MASTER_SCHOOL_PRINCIPAL.getUserCode().equals(userCode);
    }

    public static Boolean isSchoolSlaver(Integer userCode) {
        return SLAVE_SCHOOL_PRINCIPAL.getUserCode().equals(userCode);
    }

    public static Boolean isSchoolLeader(Integer userCode) {
        return isSchoolMaster(userCode) || isSchoolSlaver(userCode);
    }

}
